<include file="public@header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:url('/company/admin_index/index')}">所有企业</a></li>
			<li class="active"><a href="{:url('company/admin_index/add')}">企业添加</a></li>
		</ul>
		<form method="post" class="form-horizontal margin-top-20 js-ajax-form" action="{:url('/company/admin_index/addpost')}">
			<div class="form-group">
				<label for="category_id" class="col-sm-2 control-label"><span class="form-required">*</span>企业分类</label>
				<div class="col-md-2">
					<select class="form-control" id="category_id" name="post[category_id]" >
						<option value="">请选择分类</option>
						<volist name="company_category" id="vo">
							<option value="{$vo.id}">{$vo.name}</option>
						</volist>
					</select>

					<input type="hidden" id="category_name" name="post[category_name]" value="">
				</div>

				<label for="nature_id" class="col-sm-2 control-label"><span class="form-required">*</span>企业性质</label>
				<div class="col-md-2">
					<select class="form-control" id="nature_id" name="post[nature_id]" >
						<option value="">请选择企业性质</option>

						<volist name="company_nature" id="vo">
							<option value="{$vo.id}">{$vo.name}</option>
						</volist>
					</select>

					<input type="hidden" id="nature_name" name="post[nature_name]" value="">
				</div>
			</div>
			<div class="form-group">
				<label for="name" class="col-sm-2 control-label"><span class="form-required">*</span>企业名称</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="name" name="post[name]">
				</div>
			</div>
			<div class="form-group">
				<label for="short_name" class="col-sm-2 control-label"><span class="form-required">*</span>企业简称</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="short_name" name="post[short_name]">
				</div>

				<label for="org_code" class="col-sm-2 control-label">组织机构代码</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="org_code" name="post[org_code]">
				</div>
			</div>

			<div class="form-group">
				<label for="description" class="col-sm-2 control-label">企业简介</label>
				<div class="col-md-6 col-sm-10">
					<textarea class="form-control" name="post[description]" id="description" style="height: 50px;"
							  placeholder="请填写简介"></textarea>
				</div>
			</div>


			<div class="form-group">
				<label for="province" class="col-sm-2 control-label"><span class="form-required">*</span>所在地区</label>
				<div class="col-md-2 col-sm-10">


					<select class="form-control" id="province" name="post[province_id]" >
						<php>$select = $districts['options'][0]['id'] == 0 ? "selected" : "";</php>
						<option value="" {$select} data-text="">请选择</option>
						<foreach name="districts['options'][0]['options']" item="vo">
							<php>$select = $districts['options'][0]['id'] == $vo['id'] ? "selected" : "";</php>
							<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
						</foreach>
					</select>
				</div>

				<div class="col-md-2 col-sm-10">

				<select class="form-control" id="city" name="post[city_id]" >
					<php>$select = $districts['options'][1]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][1]['options']" item="vo">
						<php>$select = $districts['options'][1]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>

				<div class="col-md-2 col-sm-10">
					<select class="form-control" id="country" name="post[country_id]" >
						<php>$select = $districts['options'][2]['id'] == 0 ? "selected" : "";</php>
						<option value="" {$select} data-text="">请选择</option>
						<foreach name="districts['options'][2]['options']" item="vo">
							<php>$select = $districts['options'][2]['id'] == $vo['id'] ? "selected" : "";</php>
							<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
						</foreach>
					</select>
				</div>



				<div class="col-md-2 col-sm-10">
					<select class="form-control" id="area" >
						<php>$select = $districts['options'][3]['id'] == 0 ? "selected" : "";</php>
						<option value="" {$select} data-text="">请选择</option>
						<foreach name="districts['options'][3]['options']" item="vo">
							<php>$select = $districts['options'][3]['id'] == $vo['id'] ? "selected" : "";</php>
							<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
						</foreach>
					</select>
				</div>

				<input type="hidden" id="province_name" name="post[province_name]" value="">

				<input type="hidden" id="city_name" name="post[city_name]" value="">

				<input type="hidden" id="country_name" name="post[country_name]" value="">

				<input type="hidden" id="district_id" name="post[district_id]" value="{$default_district}">
				<input type="hidden" id="district_name" name="post[district_name]" value="{$districts['name']}">


			</div>

			<div class="form-group">
				<label for="input-address" class="col-sm-2 control-label"><span class="form-required">*</span>详细地址</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-address" name="post[address]">
				</div>
			</div>

			<div class="form-group">
				<label for="postcode" class="col-sm-2 control-label">邮政编码</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="postcode" name="post[postcode]">
				</div>

				<label for="gps" class="col-sm-2 control-label">坐标</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="gps" name="post[gps]">
				</div>
			</div>


			<div class="form-group">
				<label for="person_count" class="col-sm-2 control-label"><span class="form-required">*</span>员工人数</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="person_count" name="post[person_count]">
				</div>

				<label for="turnover" class="col-sm-2 control-label">营业额（万元）</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="turnover" name="post[turnover]">
				</div>
			</div>

			<div class="form-group">
				<label for="selling_area" class="col-sm-2 control-label">营业面积（M<sup>2</sup>）</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="selling_area" name="post[selling_area]">
				</div>

				<label for="input-founding_time" class="col-sm-2 control-label">成立时间</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control js-bootstrap-date" id="input-founding_time" name="post[founding_time]">
				</div>
			</div>


			<div class="form-group">
				<label for="input-contact_person" class="col-sm-2 control-label"><span class="form-required">*</span>联系人</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="input-contact_person" name="post[contact_person]">
				</div>

				<label for="contact_person_phone" class="col-sm-2 control-label"><span class="form-required">*</span>电话</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="contact_person_phone" name="post[contact_person_phone]">
				</div>
			</div>

			<div class="form-group">
				<label for="contact_person_email" class="col-sm-2 control-label">邮箱</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="contact_person_email" name="post[contact_person_email]">
				</div>

				<label for="contact_person_job" class="col-sm-2 control-label"><span class="form-required">*</span>职位</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control" id="contact_person_job" name="post[contact_person_job]">
				</div>
			</div>

			<div class="form-group">
				<label for="contact_person_birthday" class="col-sm-2 control-label">出生日期</label>
				<div class="col-md-2 col-sm-10">
					<input type="text" class="form-control js-bootstrap-date" id="contact_person_birthday" name="post[contact_person_birthday]">
				</div>

				<label for="contact_person_sex" class="col-sm-2 control-label"><span class="form-required">*</span>性别</label>
				<div class="col-md-2 col-sm-10">
					<select class="form-control" id="contact_person_sex" name="post[contact_person_sex]" >


						<option value="">请选择性别</option>
						<php>

							$personSex = config('person_sex');
							if (!empty($personSex)) {

								foreach ($personSex as $key=>$value) {
								echo "<option value='$key'>$value</option>";
								}

							}

						</php>
					</select>

				</div>
			</div>

			<div class="form-group">
				<label for="member_level_id" class="col-sm-2 control-label"><span class="form-required">*</span>会员等级</label>
				<div class="col-md-2 col-sm-10">
					<select class="form-control" id="member_level_id" name="post[member_level_id]" >
						<volist name="member_level" id="vo">
							<option value="{$vo.id}">{$vo.name}</option>
						</volist>
					</select>

					<input type="hidden" id="member_level_name" name="post[member_level_name]" value="">
				</div>

				<label for="member_quality_id" class="col-sm-2 control-label"><span class="form-required">*</span>会员质量</label>
				<div class="col-md-2 col-sm-10">
					<select class="form-control" id="member_quality_id" name="post[member_quality_id]" >
						<volist name="member_quality" id="vo">
							<option value="{$vo.id}">{$vo.name}</option>
						</volist>
					</select>

					<input type="hidden" id="member_quality_name" name="post[member_quality_name]" value="">
				</div>
			</div>


			<div class="form-group">
				<label for="member_status_id" class="col-sm-2 control-label"><span class="form-required">*</span>状态</label>
				<div class="col-md-2 col-sm-10">
					<select class="form-control" id="member_status_id" name="post[member_status_id]" >
						<volist name="member_status" id="vo">
							<option value="{$vo.id}">{$vo.name}</option>
						</volist>
					</select>

					<input type="hidden" id="member_status_name" name="post[member_status_name]" value="">
				</div>

				<label class="col-sm-2 control-label">是否连锁</label>
				<div class="col-md-6 col-sm-10">

					<php>

						$companyChain = config('company_chain');
						if (!empty($companyChain)) {

						foreach ($companyChain as $key=>$value) {
						 $checked="";
						 if($key=="N"){
							$checked="checked";
							}
						echo "<label class='radio-inline'><input type='radio' name='post[is_chain]' value='$key' $checked>$value</label>";
						}

						}

					</php>


				</div>
			</div>



			<div class="form-group">
				<label   class="col-sm-2 control-label">企业资质</label>

				<div class="col-md-6 col-sm-10">
					<ul id="files" class="pic-list list-unstyled form-inline">
					</ul>
					<a href="javascript:uploadMultiImage('附件上传','#files','files-item-tpl');"
					   class="btn btn-sm btn-default">选择文件</a>
				</div>
			</div>





			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
				</div>
			</div>
		</form>
	</div>

	<script type="text/html" id="files-item-tpl">
		<li id="saved-file{id}">
			<input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
			<input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
				   style="width: 200px;" title="文件名称">
			<a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
			<a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
			<a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
		</li>
	</script>



	<link rel="stylesheet" href="__STATIC__/js/select2/css/select2.min.css">

	<script src="__STATIC__/js/select2/js/select2pinyin.js?v=201802271547"></script>

	<script>

        $(function () {
            var $province = $("#province");
            var $city = $("#city");
            var $country = $("#country");
            var $area = $("#area");
            var $district_id = $("#district_id");
            var $district_name = $("#district_name");

            var empty = "<option value='' data-text=''>请选择</option>";

            $province.select2();
            $city.select2();
            $country.select2();
            $area.select2();

            $province.on('change', function () {
                var province = $province.find("option:selected");
                if (province.val().length == 0) {
                    $city.html(empty);
                    $country.html(empty);
                    $area.html(empty);
                    $district_id.val(0);
                } else {
                    $.post("{:url('/company/admin_index/district')}", {parentid: province.val(), type: "json"}, function (data) {
                        var options = empty;
                        for (var i = 0; i < data.data.length; i++) {
                            options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                        }
                        $city.html(options);
                        $country.html(empty);
                        $area.html(empty);
                    });
                    $district_id.val(province.val());
                }
                $district_name.val(province.data("text"));
            });
            $city.on('change', function () {
                var province = $province.find("option:selected");
                var city = $city.find("option:selected");
                if (city.val().length == 0) {
                    $country.html(empty);
                    $area.html(empty);
                    $district_id.val(province.val());
                } else {
                    $.post("{:url('/company/admin_index/district')}", {parentid: city.val(), type: "json"}, function (data) {
                        var options = empty;
                        for (var i = 0; i < data.data.length; i++) {
                            options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                        }
                        $country.html(options);
                        $area.html(empty);
                    });
                    $district_id.val($city.val());
                }
                $district_name.val(province.data("text") + city.data("text"));
            });
            $country.on('change', function () {
                var province = $province.find("option:selected");
                var city = $city.find("option:selected");
                var country = $country.find("option:selected");
                if (country.val().length == 0) {
                    $area.html(empty);
                    $district_id.val(city.val());
                } else {
                    $.post("{:url('/company/admin_index/district')}", {parentid: country.val(), type: "json"}, function (data) {
                        var options = empty;
                        for (var i = 0; i < data.data.length; i++) {
                            options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                        }
                        $area.html(options);
                    });
                    $district_id.val(country.val());
                }
                $district_name.val(province.data("text") + city.data("text") + country.data("text"));
            });
            $area.on('change', function () {
                var province = $province.find("option:selected");
                var city = $city.find("option:selected");
                var country = $country.find("option:selected");
                var area = $area.find("option:selected");
                $district_name.val(province.data("text") + city.data("text") + country.data("text") + area.data("text"));
                if (area.val().length == 0) {
                    $district_id.val(country.val());
                } else {
                    $district_id.val(area.val());
                }
            });

        })

        $("form").submit(function(e){


            $("#province_name").val($("#province").find("option:selected").data("text"));

            $("#city_name").val($("#city").find("option:selected").data("text"));
            $("#country_name").val($("#country").find("option:selected").data("text"));

            $("#category_name").val($("#category_id").find("option:selected").text());
            $("#nature_name").val($("#nature_id").find("option:selected").text());
            $("#member_level_name").val($("#member_level_id").find("option:selected").text());
            $("#member_quality_name").val($("#member_quality_id").find("option:selected").text());
            $("#member_status_name").val($("#member_status_id").find("option:selected").text());

            //return false;
        });

	</script>
	<script src="__STATIC__/js/admin.js"></script>
</body>
</html>